#pragma once

#include <string>

#include "gl_util.h"

using namespace std;

class Shader {
public:
	Shader();

	string attachVertexSource(const char *src) { return attachSource(src, GL_VERTEX_SHADER_ARB); }
	string attachFragmentSource(const char *src) { return attachSource(src, GL_FRAGMENT_SHADER_ARB); }

	string link();

	void start();
	void stop();

	void setUniform(const char *name, float f);
	void setUniform(const char *name, vec2 &v);
	void setUniform(const char *name, vec3 &v);
	void setUniform(const char *name, vec4 &v);

	void setUniform(const char *name, mat4 &m);
private:
	GLhandleARB program;
	bool linked;

	string attachSource(const char *src, GLenum type);
};

template<>
class UseHandle<Shader> : public SuperUseHandle {
	Shader &s;
public:
	UseHandle(Shader &s) : s(s) { s.start(); }
	~UseHandle() { s.stop(); }
};